package com.whiteape.book;

import android.app.Application;

import com.meituan.android.walle.WalleChannelReader;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.socialize.PlatformConfig;
import com.whiteape.book.common.WaConstants;

import io.reactivex.functions.Consumer;
import io.reactivex.plugins.RxJavaPlugins;


public class WaApp extends Application {

    private static WaApp instance;

    public static WaApp getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        String channel = WalleChannelReader.getChannel(this);
        UMConfigure.init(this, WaConstants.UMENG_APPID, channel, UMConfigure.DEVICE_TYPE_PHONE, null);
        PlatformConfig.setWeixin(WaConstants.WX_APPID, WaConstants.WX_APP_SECRET);
        PlatformConfig.setQQZone(WaConstants.QQ_APPID, WaConstants.QQ_APP_KEY);

        // 选用AUTO页面采集模式
        MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
        // 这里实现SDK初始化，appId替换成你的在Bugly平台申请的appId
        // 调试时，将第三个参数改为true
        Bugly.init(this, WaConstants.BUGLY_APP_ID, false);
        Bugly.setAppChannel(this, channel);
        Beta.autoInit = true;
        Beta.autoCheckUpgrade = true;

        RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
//                LogUtil.e("RxJava catch global exception", throwable);
            }
        });
    }

}
